package fhp.hlhj.giantfold.activity.user

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.InputFilter
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.event.RefreshInfoEvnet
import fhp.hlhj.giantfold.interfaces.IChangeInfo
import fhp.hlhj.giantfold.javaBean.ChangeInfoBean
import fhp.hlhj.giantfold.presenter.ChangeInfoPresenter
import fhp.hlhj.giantfold.utils.MyUtils
import kotlinx.android.synthetic.main.activity_user_nick_aty.*
import org.greenrobot.eventbus.EventBus

class UserNickAty : BaseActivity(),IChangeInfo {
    private lateinit var presenter:ChangeInfoPresenter
    override fun getContentId(): Int = R.layout.activity_user_nick_aty

    override fun initView() {
        presenter= ChangeInfoPresenter(this)
        etNick.filters=arrayOf<InputFilter>(InputFilter.LengthFilter(12))
    }

    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
        btCommit.setOnClickListener {
            val params = HttpParams()
            params.put("column_name","nick_name")
            params.put("new_value",etNick.text.toString())
            params.put("user_id",Contents.userId)
            presenter.changeInfo(params)
        }
    }


    override fun changeInfo(changeInfoBean: ChangeInfoBean) {
        loadingDialog.dismiss()
        if (changeInfoBean.code==200){
            MyUtils.toast("修改成功")
            EventBus.getDefault().post(RefreshInfoEvnet())
            finish()
        }
    }

    override fun showLoading() {
        loadingDialog.show()
    }

}
